﻿using System;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace DALT.Controls.Converters
{
    [ValueConversion(typeof(string), typeof(ImageSource))]
    public class UriToImageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Returns an image from value, which is a string representing the path to the image
            Uri imagePath = new Uri(value.ToString(), UriKind.RelativeOrAbsolute);
            ImageSource source = new BitmapImage(imagePath);
            return source;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

/* Singleton code removed - is it necessary?
static UriToImageConverter()
        {
            Instance = new UriToImageConverter();
        }

        public static UriToImageConverter Instance
        {
            get;
            private set;
        }
*/